Skip to main content

private

Type

keyword

Summary

The private keyword makes a function or command local to the script in which it is present

Syntax

private {command|function} <handlerName> <parameterList>

Description

Use the private keyword to declare a function or command as local to the object whose script it is in and stop it being directly called by any other objects.

Whenever an implicit handler call is made (ie calling the handler simply by its name as opposed to using send or call), LiveCode will check the current script for a private handler before allowing the call to pass through the message path. If a private handler is found in the current script, it will be directly called.

note

Attempting to compile a private handler containing a pass control structure will cause a compilation error because private handlers cannot be passed through the message path.

The use of private handlers for functionality local to a particular object is recommended as it encourages better encapsulation and helps avoid problems with namespace pollution caused by multiple handlers in the message path with the same name.

Using private handlers when appropriate will also result in a performance gain as fewer messages are passed through the message path.

note

Although it is also possible to use on when declaring a private handler this is not recommended as it implies that the handler is a message sent when some event occurs. As private handlers are not passed through the message path, this is incorrect and can make the code harder to understand. Please see the on control structure entry for more details.

Parameters

NameTypeDescription

handlerName

The name of the handler

parameterList

A comma-delimited list of the parameters

Examples

private command someLocalCommand pParameter1, pParameter2
-- do something
end someLocalCommand
private function someLocalFunction
-- do something
end someLocalFunction

control structure: pass, on, function

glossary: command, function

Compatibility and Support

Introduced

LiveCode 2.8.1

OS

mac

windows

linux

ios

android

Platforms

desktop

server

mobile

Thank you for your feedback!

Was this page helpful?